//
//  HPSignInTextField.m
//  HappyPenguin
//
//  Created by zhuangyihang on 1/11/16.
//  Copyright © 2016 zhuangyihang. All rights reserved.
//

#import "HPSignInTextField.h"

@interface HPSignInTextField()

@property (nonatomic, strong) UIView *sepView;

@end

@implementation HPSignInTextField

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)init{
    self = [super init];
    if (self) {
        UIView *sep = [UIView new];
        [self addSubview:sep];
        [sep mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.width.centerX.equalTo(self);
            make.height.equalTo(@1);
        }];
        sep.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.8];
        
        self.iconImageView = [UIImageView new];
        [self addSubview:self.iconImageView];
        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@30);
            make.left.centerY.equalTo(self);
        }];
        self.iconImageView.contentMode = UIViewContentModeCenter;
        
        UIView *sep2 = [UIView new];
        [self addSubview:sep2];
        [sep2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@1);
            make.top.equalTo(self);
            make.bottom.equalTo(self).offset(-7);
            make.left.equalTo(self.iconImageView.mas_right).offset(4);
        }];
        sep2.backgroundColor = [UIColor whiteColor];
        self.sepView = sep2;
        
        self.textField = [UITextField new];
        [self addSubview:self.textField];
        self.textField.bk_shouldReturnBlock = ^(UITextField *textField){
            [textField resignFirstResponder];
            return YES;
        };
        [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(sep2.mas_right).offset(7);
            make.centerY.equalTo(self.iconImageView);
            make.height.equalTo(self);
            make.right.equalTo(self);
        }];
    }
    return self;
}

- (void)setImageViewHidden:(BOOL)hidden{
    if (hidden) {
        [self.textField mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.height.centerY.equalTo(self);
        }];
        [self.sepView removeFromSuperview];
        self.sepView = nil;
        [self.iconImageView removeFromSuperview];
        self.iconImageView = nil;

    }
}

@end
